import type { RouteRecordRaw } from 'vue-router'

// 扩展的路由记录类型
export type AppRouteRecordRaw = RouteRecordRaw & {
  meta: {
    title: string
    icon: string
    closable: boolean
  }
  children?: AppRouteRecordRaw[]
}

// 所有路由信息
export const routes: AppRouteRecordRaw[] = [
  {
    name: 'MainLayout',
    path: '/',
    redirect: '/shouye',
    component: () => import('layouts/MainLayout.vue'),
    meta: {
      title: '布局',
      icon: 'notes',
      closable: false,
    },
    children: [
      {
        name: 'MainLayoutPage',
        path: '/shouye',
        component: () => import('pages/IndexPage.vue'),
        meta: {
          title: '首页',
          icon: 'notes',
          closable: false,
        },
      },
      {
        name: 'DemoPage',
        path: '/demo',
        component: () => import('pages/demo/index.vue'),
        meta: {
          title: '测试',
          icon: 'build',
          closable: true,
        },
      },
      {
        name: 'DemoPage2',
        path: '/demo2',
        component: () => import('pages/demo/d2Page.vue'),
        meta: {
          title: '测试2',
          icon: 'build',
          closable: true,
        },
      },
      {
        path: '/manage',
        meta: {
          title: '系统管理',
          icon: 'settings_suggest',
          closable: true,
        },
        children: [
          {
            name: 'UserPage',
            path: '/manage/user',
            component: () => import('pages/manage/user/index.vue'),
            meta: {
              title: '用户管理',
              icon: 'account_box',
              closable: true,
            },
          },
          {
            name: 'RolePage',
            path: '/manage/role',
            component: () => import('pages/manage/role/index.vue'),
            meta: {
              title: '角色管理',
              icon: 'people_alt',
              closable: true,
            },
          },

          {
            name: 'MenuPage',
            path: '/manage/menu',
            component: () => import('pages/manage/menu/index.vue'),
            meta: {
              title: '菜单管理',
              icon: 'apps',
              closable: true,
            },
          },
        ],
      },
    ],
  },

  // 登录页面
  {
    name: 'LoginPage',
    path: '/login',
    component: () => import('pages/login/index.vue'),
    meta: {
      title: '登录',
      icon: 'login',
      closable: true,
    },
  },

  // 以上都不匹配，则报404,
  {
    path: '/:catchAll(.*)*',
    component: () => import('pages/404/index.vue'),
    meta: {
      title: 'not F',
      icon: 'not',
      closable: true,
    },
  },
]

/**
 * 路由菜单信息（仅包含'/'的子菜单）
 * ?? : 当左侧值是null 或undefined 时才取右侧[]
 * || : 左侧值包含了null或undefined 之外，还包括(0、''、false、NaN)
 * 特别说明： []、{} 本身就是真，不可判断真假，真假包括6个（null、undefined、0、''、false、NaN）
 */
export const root_routes: AppRouteRecordRaw[] =
  (routes.find((r) => r.path == '/')?.children as AppRouteRecordRaw[]) ?? []
